/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gad.ui;

import java.awt.Color;
import java.awt.Dimension;
import org.gad.model.CompositeStep;
import org.gad.model.ExampleStep;
import org.gad.model.Step;
import org.netbeans.api.visual.border.BorderFactory;
import org.netbeans.api.visual.layout.LayoutFactory;
import org.netbeans.api.visual.widget.Widget;

/**
 *
 * @author Tomek
 */
public abstract class CompositeStepWidget extends StepWidgetBase
{

    protected ExpandButtonWidget _expandButton;
    protected Widget _clientAreaBorder;
    protected Widget _clientArea;
    protected Widget _bottomWidget;

    public CompositeStepWidget(BoxScene scene, Step modelStep)
    {
        super(scene, modelStep);
        //this.setBorder(BorderFactory.createEmptyBorder());
        _clientAreaBorder = new Widget( scene );
        _clientAreaBorder.setLayout(LayoutFactory.createOverlayLayout());
        
        _clientAreaBorder.setOpaque(true);
        //_clientAreaBorder.setBackground(Color.RED);
        
        _clientArea = new Widget( _scene );
        _clientArea.setLayout(Layouts.VerticalLayoutSpaced );
        _clientArea.setBorder(BorderFactory.createEmptyBorder(25));
        _clientArea.setMinimumSize(Dimensions.StepMinSize);
        
        _clientAreaBorder.addChild(_clientArea);
        _mainVFlow.addChild(_clientAreaBorder);
        
        
        _mainVFlow.setOpaque(true);
        _mainVFlow.setBackground( new Color( 212,244, 255));
        
        _bottomWidget = new Widget(scene);
        _bottomWidget.setMinimumSize(new Dimension( Dimensions.StepMinSize.width , 0));
        _mainVFlow.addChild(_bottomWidget);
        
        _expandButton = new ExpandButtonWidget(scene, new IExpandButtonListener()
        {

            public void ExpandChanged(boolean isExpanded)
            {
                _clientAreaBorder.setVisible(isExpanded);
//                for (Widget w : _clientArea.getChildren())
//                {
//                    w.setVisible(isExpanded);
//                }
            }
        });
        
        _headerVFlow.addChild(new ButtonWidget(scene, "+", new IButtonClickListener() {

            public void Click()
            {
                ((CompositeStep)_modelStep).AddStep(new ExampleStep("Deferred1"));
            }
        }));

        _headerVFlow.addChild(_expandButton);
        
        //_clientArea.setBorder(BorderFactory.createRoundedBorder(0, 0, Color.WHITE, Color.LIGHT_GRAY));
    }

    public abstract void addInnerStep(StepWidgetBase step);

    public abstract void removeInnerStep( StepWidgetBase step );
}
